package hz.mobileproject.pda.presenter;


import android.content.Context;
import android.util.Log;

import com.google.gson.Gson;

import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;
import hz.mobileproject.pda.entity.request.Request_data;
import hz.mobileproject.pda.entity.response.Response_data;
import hz.mobileproject.pda.network.Api;
import hz.mobileproject.pda.ui.activity.work.KeyPlace_logActivity;
import hz.mobileproject.pda.utils.Base64;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/7/11 0011.
 */

public class PKeyPlace extends XPresent<KeyPlace_logActivity> {
    private Gson gson;
    private Request_data data;
    private String body_data;
    private RequestBody body;
    private String token;


    public PKeyPlace() {
        gson = new Gson();
        data = new Request_data();

    }

    public void uploadData(String request_data ,String type){
        data.setData(Base64.getBase64(request_data));
        body_data=  gson.toJson(data);
        this.token = getV().getApplicationContext().getSharedPreferences("app_login", Context.MODE_PRIVATE).getString("token","");
    }

    public void loadData(Object request_data ,int type){
        String date= gson.toJson(request_data);
        Log.e("load",date);
        data.setData(Base64.getBase64(date));
        body_data=  gson.toJson(data);
        body= RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),body_data);
        getDataBody(body,type);
    }


    private void getDataBody(RequestBody body,int type) {
        switch (type){
            case 1: {    //获取所有已点重点部位
                Api.getGankService().getAllYiDianImp(body,token)
                        .compose(XApi.<Response_data>getApiTransformer())
                        .compose(XApi.<Response_data>getScheduler())
                        .subscribe(new ApiSubscriber<Response_data>() {
                            @Override
                            protected void onFail(NetError error) {

                            }

                            @Override
                            public void onNext(Response_data response_data) {
                                getV().showData(Base64.getFromBase64(response_data.getData()),1);
                            }
                        });

            }
            break;
            case 2:

                break;
            case 3:

                break;
            case 4:


                break;

        }



    }



}

